import psutil
import GPUtil

def get_cpu_info():
    cpu_percent = psutil.cpu_percent(interval=1)
    cpu_count = psutil.cpu_count(logical=True)
    cpu_freq = psutil.cpu_freq()
    return {
        "cpu_percent": cpu_percent,
        "cpu_count": cpu_count,
        "cpu_freq": {
            "current": cpu_freq.current,
            "min": cpu_freq.min,
            "max": cpu_freq.max
        }
    }

def get_gpu_info():
    gpus = GPUtil.getGPUs()
    gpu_info = []
    for gpu in gpus:
        gpu_info.append({
            "id": gpu.id,
            "name": gpu.name,
            "load": gpu.load,
            "memoryTotal": gpu.memoryTotal,
            "memoryUsed": gpu.memoryUsed,
            "memoryFree": gpu.memoryFree,
            "temperature": gpu.temperature
        })
    return gpu_info

def get_memory_info():
    memory = psutil.virtual_memory()
    return {
        "total": memory.total,
        "available": memory.available,
        "used": memory.used,
        "percent": memory.percent
    }

def get_disk_info():
    print(psutil.getloadavg())
    partitions = psutil.disk_partitions()
    disk_info = []
    total_size = 0
    for partition in partitions:
        usage = psutil.disk_usage(partition.mountpoint)
        total_size += usage.used
        disk_info.append({
            "device": partition.device,
            "mountpoint": partition.mountpoint,
            "fstype": partition.fstype,
            "total": usage.total,
            "used": usage.used,
            "free": usage.free,
            "percent": usage.percent
        })
    return disk_info,total_size

if __name__ == "__main__":
    print("CPU Info:", get_cpu_info())
    print("GPU Info:", get_gpu_info())
    print("Memory Info:", get_memory_info())
    print("Disk Info:", get_disk_info())
